LeetCode: Ruby: ListNode
code:rb
class ListNode
attr_accessor :val, :next
def initialize(val)
@val = val
@next = nil
end
end
ln1 = ListNode.new(1)
ln2 = ListNode.new(2)
ln3 = ListNode.new(3)
ln4 = ListNode.new(4)
ln5 = ListNode.new(5)
ln1.next = ln2
ln2.next = ln3
ln3.next = ln4
ln4.next = ln5
p ln1 # => #<ListNode:0x007fbd46967138 @val=1, @next=#<ListNode:0x007fbd469670c0 @val=2, @next=#<ListNode:0x007fbd46967048 @val=3, @next=#<ListNode:0x007fbd46967020 @val=4, @next=#<ListNode:0x007fbd46966ff8 @val=5, @next=nil>>>>>